package com.drumbeatinsight.services.wordpress {
	
	public class Utils {
		
		// add more here
   		public static var findLineBreaksPattern:RegExp = /\r?\n+?/g;
   		public static var strongStartPattern:RegExp = /<strong>/gi;
   		public static var strongEndPattern:RegExp = /<\/strong>/gi;
   		public static var italicsStartPattern:RegExp = /<em>/gi;
   		public static var italicsEndPattern:RegExp = /<\/em>/gi;
   		public static var imageTagSource:RegExp = /<img[^>]*src="(?P<src>[^"]*)"[^>]*>/gim;
   		
		public static function formatText(string:String):String {
			if (string==null) { return ""; }
			
			// replace linebreaks with <br> tags
			string = string.replace(findLineBreaksPattern,"<br/>");
			string = string.replace(strongStartPattern,"<b>");
			string = string.replace(strongEndPattern,"</b>");
			
			return string;
			
		}
		
		public static function getImageSource(string:String):String {
			if (string==null) { return ""; }
			
			var matches:Array = new Array();
			
			// get image src
			matches = imageTagSource.exec(string);
			string = (matches!=null && matches.hasOwnProperty("src")) ? matches.src : "";
			return string;
		}
		
		public static function getImageHTML(string:String):String {
			if (string==null) { return ""; }
			
			var matches:Array;
			
			// get image html markup
			matches = string.match(imageTagSource);
			string = (matches.length > 0) ? matches[0] : "";
			
			return string;
		}
	}
}